<?php
namespace app\index\controller;

use think\Db;
use think\Request;
/**
* 各大平台接口
*
* 作用：实现采集，登录别人的网站
* Curl->Client URL Library客户端url库
* file_get_contents 文件获取    //重点
*/
class Api extends \think\Controller
{
	public function demo(){
		dump("演示一下 api跨域访问");

		$url = "http://localhost/tp5/public/index.php/index/bbs/bbsadd";
		// $url = file_get_contents($url);


		// echo $url;
		// echo $url;//输出页面
		// dump($url);//输出源文件


		$data = array(
			"title"=>"用机器人来发帖了，我来采集你的内容了",
			"content"=>"加个验证码吧，不然被攻击了"
			);

		//1.s
		$ch = curl_init();

		//2.设置选项，包括URL
		
		//指定请求的URL
		curl_setopt($ch, CURLOPT_URL,$url);
		// curl_setopt($curl, CURLOPT_URL, $url);
		// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,60);
		// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,1);
		// curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,"username:password");
		curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));


		//放回字符串
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

		//3.执行并获取HTML文档内容
		$output = curl_exec($ch);

		//4.释放curl句柄
		curl_close($ch);


		// echo $output;


	}
	public function yuming(){//域名接口（跨域访问）
		$domain = 'Rinuo.com';
		$cha = 'http://panda.www.net.cn/cgi-bin/check.cgi?area_domain='.$domain;
		$fp = file_get_contents($cha,'rb');
		
		// dump($fp);exit();

		$xml = simplexml_load_string($fp);
		$data = json_decode(json_encode($xml),true);//转化成数组
		// dump($fp);dump($data);exit();


		//模板变量赋值
		$this->assign('name','<h1>^_^</h1>R\uo');
		//dump($data);
		
		$this->assign('data',$data);

		//渲染模板输出
		return $this->fetch();
	}

	public function weibo(){//未完成  微博开发者平台认证三个工作日6-21开始认证  
		/*
		 * 发起请求
		 * 接收返回数据
		 * 请求用户信息
		 * 存入数据库
		 */
		

		// https://open.weibo.com/wiki/Connect/login
		// https://open.weibo.com/wiki/2/users/show  //错误代码
		
		$code = input('code');

		echo $code;
		//exit();

		$tom = "https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI";

		// post获取开始 获取重要的唯一ID
		$url = $tom;
		//ehco $url.'<br />';
		header("Content-Type:text/html;charset=utf-8");
		$curl = curl_init();
		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,false);
		curl_setopt($curl, CURLOPT_POST,TRUE);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,1);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,"username:password");
		$data = curl_exec($curl);
		curl_close($curl);
		$result = json_decode($data,true);

		echo '<pre>';
		print_r($result);
		echo '<pre>';

		exit();

		
		$access_token = $result['access_token'];
		$uid = $result['uid'];
		//echo $access_token;exit();
		

		//继续获得用户信息 - 开始 方法一
		$tom = "https://api.weibo.com/2/users/show.json?access_token=".$access_token."&uid=".$uid;


		//使用file方法
		$data = file_get_contents($tom,'rb');
		
		// dump($fp);exit();
		



		$data = json_decode($data,true);//转化成数组

		$this->assign('data',$data);

		return $this->fetch();
	}
	//支付宝支付接口
	public function zhifubao(){


	}
	//短信验证码接口
	public function sms(){
		$tom = '15070942969';
		$tom = input('s');
		$cha = '填入短信接口链接'；
		$fp = file_get_contents($cha,'rb');
		//dump($fp);
		
		$xml = simplexml_load_string($fp);
		$data = json_decode(json_encode($xml),TRUE);

		//dump($data);
		
		echo $data['message'];

		//return $this->fetch();
	}
}

